package com.wms.dss.ats.customs.abb.utils;

import com.ricosoft.common.logger.Logger;

import java.io.Serializable;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 描述:cyc16校验码
 * @author zhu
 *
 */
public class Tools implements Serializable
{
	public static void main1(String[] g)
	{
		String xx = "m000025"; //8个字节
		long ss = 25;
		int xda = 0xFFFF ; 
		int zz = 0;
		int[] ff = new int[2];
		ff[0] =10;
		ff[1] =8;

		int  xctaskno =154;
		byte xczlgs =2;
		byte xcylh = 1;
		byte xcmlh = 8;
		byte xdbz = 1;
		
		int  ddjtaskno =154;
		byte ddjzlgs =2;
		byte ddjmbp = 2;
		byte ddjmbl = 3;
		byte ddjmbc = 16;
		byte ddjxdbz = 1;
		
		int  ssjtaskno =152;
		byte ssjxdbz =1;
		/*System.out.println(getJYMCRC16(xx,taskno));	*/
		System.out.println(getXCJYMCRC16( xctaskno, xczlgs, xcylh, xcmlh, xdbz));	
		System.out.println(getDDJJYMCRC16( ddjtaskno, ddjzlgs, ddjmbp, ddjmbl, ddjmbc, ddjxdbz));
		System.out.println(getSSJJYMCRC16( ssjtaskno, ssjxdbz));
		/*System.out.println(printBits(taskno));
		System.out.println(0xA001);
		System.out.println(0xFFE6&0x01); //&两个位都是1，结果才是1
		System.out.println((xda ^= 25)&0x01); //&两个位都是1，结果才是1
		System.out.println(BytesToInt(ff));*/
	}
	public static void main(String arg[]){
		
		
		//int jym_ckd_rgcrpdds = getJYM_ckd_zc_dd_xczt(1106782,4,5,1,2,1,4,1);
		//System.out.println(jym_ckd_rgcrpdds);
		/*while(true){
			try {
				Hashtable hsTask2 = new Hashtable();
				hsTask2.put("1", "343");
				long i = 1;
				String xx = (String) hsTask2.get(i+"");
				System.out.println("23423");
				break;
			} catch (Exception e) {
				// TODO: handle exception
			} finally{
				String ss ="0";
				System.out.println("ss");
			}
		}*/
		//System.out.println("12321");
	}
	public static int getSSJJYMCRC16(int ssjtaskno,byte ssjxdbz){
		int[] trayarry = new int[3];
		int[] task = binarysToints16(printBits(ssjtaskno));
		System.arraycopy(task, 0, trayarry, 0, task.length);
		trayarry[2] = binarysToints8(printBits(ssjxdbz));

		
		int[] d1=crc(trayarry);
		for(int i=0;i<d1.length;i++)
		System.out.print(d1[i]+" ");
		System.out.println();

		int[] b= new int[2];
		//**将a数组经过crc16多出来的两个字节 反转 能后存到另外一个两个字节的数组中**//*
		for(int i=2,j=0;i>0;i--,j++){
			b[j] = (int)d1[i-1+trayarry.length];
		}
		return BytesToInt(b);
	}
	public static int getDDJJYMCRC16(int ddjtaskno,byte ddjzlgs,byte ddjmbp,byte ddjmbl,byte ddjmbc,byte ddjxdbz){
		int[] trayarry = new int[7];
		int[] task = binarysToints16(printBits(ddjtaskno));
		System.arraycopy(task, 0, trayarry, 0, task.length);
		trayarry[2] = binarysToints8(printBits(ddjzlgs));
		trayarry[3] = binarysToints8(printBits(ddjmbp));
		trayarry[4] = binarysToints8(printBits(ddjmbl));
		trayarry[5] = binarysToints8(printBits(ddjmbc));
		trayarry[6] = binarysToints8(printBits(ddjxdbz));

		
		int[] d1=crc(trayarry);
		for(int i=0;i<d1.length;i++)
		System.out.print(d1[i]+" ");
		System.out.println();

		int[] b= new int[2];
		//**将a数组经过crc16多出来的两个字节 反转 能后存到另外一个两个字节的数组中**//*
		for(int i=2,j=0;i>0;i--,j++){
			b[j] = (int)d1[i-1+trayarry.length];
		}
		return BytesToInt(b);
	}
	public static int getXCJYMCRC16(int taskno,byte xczlgs,byte xcylh,byte xcmlh,byte xdbz){
		int[] trayarry = new int[6];
		int[] task = binarysToints16(printBits(taskno));
		System.arraycopy(task, 0, trayarry, 0, task.length);
		trayarry[2] = binarysToints8(printBits(xczlgs));
		trayarry[3] = binarysToints8(printBits(xcylh));
		trayarry[4] = binarysToints8(printBits(xcmlh));
		trayarry[5] = binarysToints8(printBits(xdbz));

		
		int[] d1=crc(trayarry);
		for(int i=0;i<d1.length;i++)
		System.out.print(d1[i]+" ");
		System.out.println();

		int[] b= new int[2];
		//**将a数组经过crc16多出来的两个字节 反转 能后存到另外一个两个字节的数组中**//*
		for(int i=2,j=0;i>0;i--,j++){
			b[j] = (int)d1[i-1+trayarry.length];
		}
		return BytesToInt(b);
	}
	/*4、CRC-16校验码计算方法：
	  常用查表法和计算法。计算方法一般都是：
	  （1）、预置1个16位的寄存器为十六进制FFFF（即全为1），称此寄存器为CRC寄存器；
	  （2）、把第一个8位二进制数据（既通讯信息帧的第一个字节）与16位的CRC寄存器的低
	         8位相异或，把结果放于CRC寄存器，高八位数据不变；
	  （3）、把CRC寄存器的内容右移一位（朝低位）用0填补最高位，并检查右移后的移出位；
	  （4）、如果移出位为0：重复第3步（再次右移一位）；如果移出位为1，CRC寄存器与多
	      项式A001（1010 0000 0000 0001）进行异或；
	  （5）、重复步骤3和4，直到右移8次，这样整个8位数据全部进行了处理；
	  （6）、重复步骤2到步骤5，进行通讯信息帧下一个字节的处理；
	  （7）、将该通讯信息帧所有字节按上述步骤计算完成后，得到的16位CRC寄存器的高、低
	         字节进行交换；
	  （8）、最后得到的CRC寄存器内容即为：CRC码。
	  以上计算步骤中的多项式A001是8005按位颠倒后的结果。
	  查表法是将移位异或的计算结果做成了一个表，就是将0~256放入一个长度为16位的寄存器中的低八位，高八位填充0，然后将该寄存器与多项式0XA001按照上述3、4步骤，直到八位全部移出，最后寄存器中的值就是表格中的数据，高八位、低八位分别单独一个表。*/
	 public static int[] crc(int[] data){
		  int[] temdata=new int[data.length+2];
		  //unsigned char alen = *aStr – 2;   //CRC16只计算前两部分       
		   int xda , xdapoly ;           
		   int i,j, xdabit ;            
		   xda = 0xFFFF ;  
		  xdapoly = 0xA001 ; // (X**16 + X**15 + X**2 + 1)   
		  for(i=0;i<data.length;i++)         
		  {         
			  xda ^= data[i] ; 
			  for(j=0;j<8;j++) {         
			   xdabit =( int )(xda & 0x01) ;  //获取 xda 最后一位值        
			   xda >>= 1 ; 
			  if( xdabit==1 ) 
			   xda ^= xdapoly ; 
			   }        
		  }    
		  System.arraycopy(data, 0, temdata, 0, data.length);
		  temdata[temdata.length-2] = (int)(xda & 0xFF) ;           
		  temdata[temdata.length-1] = (int)(xda>>8);     
		  return temdata;
	}
	 public static int getJYM_dd_ddj(int taskno,int YP,int YL, int YC,int MBP,int MBL,int MBC,int mbdz1,int MLFS,int xfwc){
			//将整形任务号转为32位，能后转为四个字节，最后转为整形组4
					int[] task = new int[4];
					task = binarysToints(printBits(taskno));
					int[] yp = new int[4];
					yp = binarysToints(printBits(YP));
					int[] yl = new int[4];
					yl = binarysToints(printBits(YL));
					int[] yc = new int[4];
					yc = binarysToints(printBits(YC));
					int[] mbp = new int[4];
					mbp = binarysToints(printBits(MBP));
					int[] mbl = new int[4];
					mbl = binarysToints(printBits(MBL));
					int[] mbc = new int[4];
					mbc = binarysToints(printBits(MBC));
					int[] mbdz = new int[4];
					mbdz = binarysToints(printBits(mbdz1));
					int[] mlfs = new int[4];
					mlfs = binarysToints(printBits(MLFS));
					int[] wc = new int[4];
					wc = binarysToints(printBits(xfwc));
					int[] trayarry = new int[40];
					for(int i=0;i<4;i++){
						trayarry[i] = task[i];
					}
					for(int i=0;i<4;i++){
						trayarry[4+i] = yp[i];
					}
					for(int i=0;i<4;i++){
						trayarry[8+i] = yl[i];
					}
					for(int i=0;i<4;i++){
						trayarry[12+i] = yc[i];
					}
					for(int i=0;i<4;i++){
						trayarry[16+i] = mbp[i];
					}
					for(int i=0;i<4;i++){
						trayarry[20+i] = mbl[i];
					}
					for(int i=0;i<4;i++){
						trayarry[24+i] = mbc[i];
					}
					for(int i=0;i<4;i++){
						trayarry[28+i] = mbdz[i];
					}
					for(int i=0;i<4;i++){
						trayarry[32+i] = mlfs[i];
					}
					for(int i=0;i<4;i++){
						trayarry[36+i] = wc[i];
					}
					int[] d1=trayarry;
					int a=0;
					for(int i=0;i<d1.length;i++){
					//System.out.print(d1[i]+" ");
					//System.out.println();
					a=a+d1[i];
					}
					return a;
		}

	 public static int getJYM_rkd_ztqr1(int taskno,int xdh,int zlxdwc){
			//将整形任务号转为32位，能后转为四个字节，最后转为整形组4
					int[] task = new int[4];
					task = binarysToints(printBits(taskno));
					int[] xd = new int[4];
					xd = binarysToints(printBits(xdh));
					int[] wc = new int[4];
					wc = binarysToints(printBits(zlxdwc));
					int[] trayarry = new int[12];
					for(int i=0;i<4;i++){
						trayarry[i] = task[i];
					}
					for(int i=0;i<4;i++){
						trayarry[4+i] = xd[i];
					}
					for(int i=0;i<4;i++){
						trayarry[8+i] = wc[i];
					}
					
					int[] d1=trayarry;
					int a=0;
					for(int i=0;i<d1.length;i++){
					//System.out.print(d1[i]+" ");
					//System.out.println();
					a=a+d1[i];
					}
					return a;
		}
	public static int getJYM_rkd_ztqr2(int taskno,int zlxdwc){
		//将整形任务号转为32位，能后转为四个字节，最后转为整形组4
		int[] task = new int[4];
		task = binarysToints(printBits(taskno));

		int[] wc = new int[4];
		wc = binarysToints(printBits(zlxdwc));
		int[] trayarry = new int[12];
		for(int i=0;i<4;i++){
			trayarry[i] = task[i];
		}

		for(int i=0;i<4;i++){
			trayarry[4+i] = wc[i];
		}

		int[] d1=trayarry;
		int a=0;
		for(int i=0;i<d1.length;i++){
			//System.out.print(d1[i]+" ");
			//System.out.println();
			a=a+d1[i];
		}
		return a;
	}

	public static int getJYM_ck_tsj(int taskno,int rwlx,int yp,int yc,int mbp,int mbc,int xfwc){
		//将整形任务号转为32位，能后转为四个字节，最后转为整形组4
		int[] task = new int[4];
		task = binarysToints(printBits(taskno));
		int[] rwlxs = new int[4];
		rwlxs = binarysToints(printBits(rwlx));
		int[] yph = new int[4];
		yph = binarysToints(printBits(yp));
		int[] ych = new int[4];
		ych = binarysToints(printBits(yc));
		int[] mbph = new int[4];
		mbph = binarysToints(printBits(mbp));
		int[] mbch = new int[4];
		mbch = binarysToints(printBits(mbc));
		int[] wc = new int[4];
		wc = binarysToints(printBits(xfwc));

		int[] trayarry = new int[16];
		for(int i=0;i<4;i++){
			trayarry[i] = task[i];
		}
		for(int i=0;i<2;i++){
			trayarry[4+i] = rwlxs[i];
		}
		for(int i=0;i<2;i++){
			trayarry[6+i] = yph[i];
		}
		for(int i=0;i<2;i++){
			trayarry[8+i] = ych[i];
		}
		for(int i=0;i<2;i++){
			trayarry[10+i] = mbph[i];
		}
		for(int i=0;i<2;i++){
			trayarry[12+i] = mbch[i];
		}
		for(int i=0;i<2;i++){
			trayarry[14+i] = wc[i];
		}

		int[] d1=trayarry;
		int a=0;
		for(int i=0;i<d1.length;i++){
			//System.out.print(d1[i]+" ");
			//System.out.println();
			a=a+d1[i];
		}
		return a;
	}
	public static int[] binarysToints(String hex){
		int[] a = new int[4];
		String hexString = change32(hex);
		a[0] = Integer.parseInt(hexString.substring(0,8),2);//将二进制字符串转为整形
		a[1] = Integer.parseInt(hexString.substring(8,16),2);
		a[2] = Integer.parseInt(hexString.substring(16,24),2);
		a[3] = Integer.parseInt(hexString.substring(24,32),2);
		return a;
	}
	public static int[] binarysToints16(String hex){
		int[] a = new int[2];
		String hexString = change16(hex);
		a[0] = Integer.parseInt(hexString.substring(0,8),2);//将二进制字符串转为整形
		a[1] = Integer.parseInt(hexString.substring(8,16),2);
		return a;
	}
	public static int binarysToints8(String hex){
		int a = 0;
		String hexString = change8(hex);
		a = Integer.parseInt(hexString.substring(0,8),2);//将二进制字符串转为整形
		return a;
	}
	public static int BytesToInt(int[] ss){
		if(ss!=null){
			String lString ="";
			for(int i=0;i<ss.length;i++){
				lString += change8(printBits(ss[i]));
			}
			int i=Integer.parseInt(lString,2);
			return i;
		}else{
			return 0;
		}	
	}
	public static int BytesToIntx(int[] ss){
		if(ss!=null){
			String lString ="";
			for(int i=0;i<ss.length;i++){
				lString +=  ss[i];
			}
			int i=Integer.parseInt(lString,2);
			return i;
		}else{
			return 0;
		}	
	}
	/**将字符转为整形**/
	public static int showAscii(char x) {
		int i = (int)x;
		return i;
	}
	/**将整形转为字符**/
	public static char showChar(int x) {
		char i = (char)x;
		return i;
	}
	/** 托盘条码解析**/
	public static String bytetostringtool(byte[] aaa) {
		String tptm = ""; 
	      for(int i=0;i<aaa.length;i++){
	          //System.out.println("一维数组:for:"+aaa[i]);
	          String x = Character.toString(showChar(aaa[i]));
	          char ddd=showChar(aaa[i]);
	          tptm=tptm+x;
	          //System.out.println(tptm);
	      }
		return tptm;
	}
	/**将整形转为二进制字符串*/	
	public static String printBits(int n){
		return Integer.toBinaryString(n);	
	}
	/**不满8位加高位加0**/
	public static String change8(String value){
		if(value!=null && !value.equals("")){
			String ss = value;
			for(int i=0;i<8-value.length();i++){
				ss = "0"+ss;
			}
			return ss;
		}else{
			return "00000000";
		}	
	}
	/**不满32位加高位加0 4个字节**/
	public static String change32(String value){
		if(value!=null && !value.equals("")){
			String ss = value;
			for(int i=0;i<32-value.length();i++){
				ss = "0"+ss;
			}
			return ss;
		}else{
			return "00000000000000000000000000000000";
		}	
	}
	/**不满16位加高位加0 4个字节**/
	public static String change16(String value){
		if(value!=null && !value.equals("")){
			String ss = value;
			for(int i=0;i<16-value.length();i++){
				ss = "0"+ss;
			}
			return ss;
		}else{
			return "0000000000000000";
		}	
	}
	/**
	 * @data:2019年8月5日
	 * @author:GaoFeng
	 * @description:
	 */
	/**
	 * @data:2019年8月5日
	 * @author:GaoFeng
	 * @description:
	 */
	public static int getJYM_ckd_rgcrpdds(int qQDQ, int stacking, int mDCS, int mCJS) {
		//将整形任务号转为32位，能后转为四个字节，最后转为整形组4
		int[] task = new int[4];
		task = binarysToints(printBits(qQDQ));
		int[] yp = new int[4];
		yp = binarysToints(printBits(stacking));
		int[] yl = new int[4];
		yl = binarysToints(printBits(mDCS));
		int[] yc = new int[4];
		yc = binarysToints(printBits(mCJS));
	
	
		int[] trayarry = new int[16];
		for(int i=0;i<4;i++){
			trayarry[i] = task[i];
		}
		for(int i=0;i<4;i++){
			trayarry[4+i] = yp[i];
		}
		for(int i=0;i<4;i++){
			trayarry[8+i] = yl[i];
		}
		for(int i=0;i<4;i++){
			trayarry[12+i] = yc[i];
		}
		
		int[] d1=trayarry;
		int a=0;
		for(int i=0;i<d1.length;i++){
		//System.out.print(d1[i]+" ");
		//System.out.println();
		a=a+d1[i];
		}
		return a;
	}
	
	////拆垛机信息下发校验码
	public static int getJYM_ckd_cdj(int JSRWH,int JSCG,int JSMDCS,int JSMCJS,int JSCDZT,int JSCLBJ,int JSHWGG,int JSXFWC){
		//将整形任务号转为32位，能后转为四个字节，最后转为整形组4
				int[] task = new int[4];
				task = binarysToints(printBits(JSRWH));
				int[] jscg = new int[4];
				jscg = binarysToints(printBits(JSCG));
				int[] jsmdcs = new int[4];
				jsmdcs = binarysToints(printBits(JSMDCS));
				int[] jsmcjs = new int[4];
				jsmcjs = binarysToints(printBits(JSMCJS));
				int[] jscdzt = new int[4];
				jscdzt = binarysToints(printBits(JSCDZT));
				int[] jsclbj = new int[4];
				jsclbj = binarysToints(printBits(JSCLBJ));
				int[] jshwgg = new int[4];
				jshwgg = binarysToints(printBits(JSHWGG));
				int[] jsxfwc = new int[4];
				jsxfwc = binarysToints(printBits(JSXFWC));
				
				int[] trayarry = new int[32];
				for(int i=0;i<4;i++){
					trayarry[i] = task[i];
				}
				for(int i=0;i<4;i++){
					trayarry[4+i] = jscg[i];
				}
				for(int i=0;i<4;i++){
					trayarry[8+i] = jsmdcs[i];
				}
				for(int i=0;i<4;i++){
					trayarry[12+i] = jsmcjs[i];
				}
				for(int i=0;i<4;i++){
					trayarry[16+i] = jscdzt[i];
				}
				for(int i=0;i<4;i++){
					trayarry[20+i] = jsclbj[i];
				}
				for(int i=0;i<4;i++){
					trayarry[24+i] = jshwgg[i];
				}
				for(int i=0;i<4;i++){
					trayarry[28+i] = jsxfwc[i];
				}
				
				int[] d1=trayarry;
				int a=0;
				for(int i=0;i<d1.length;i++){
				//System.out.print(d1[i]+" ");
				//System.out.println();
				a=a+d1[i];
				}
				return a;
	}
	///
////拆垛机信息下发校验码
	public static int getJYM_ckd_cdj_xz(int JSRWH,int JSXFWC){
		//将整形任务号转为32位，能后转为四个字节，最后转为整形组4
				int[] task = new int[4];
				task = binarysToints(printBits(JSRWH));
				int[] jsxfwc = new int[4];
				jsxfwc = binarysToints(printBits(JSXFWC));
				
				int[] trayarry = new int[8];
				for(int i=0;i<4;i++){
					trayarry[i] = task[i];
				}
				
				for(int i=0;i<4;i++){
					trayarry[4+i] = jsxfwc[i];
				}
				
				int[] d1=trayarry;
				int a=0;
				for(int i=0;i<d1.length;i++){
				//System.out.print(d1[i]+" ");
				//System.out.println();
				a=a+d1[i];
				}
				return a;
	}
	public static int getJYM_mdss_tsj(int taskno, int rwlx, int yc,int mbc, int xfwc, int hczxjd) {
		//将整形任务号转为32位，能后转为四个字节，最后转为整形组4
		int[] task = new int[4];
		task = binarysToints(printBits(taskno));
		int[] lx = new int[4];
		lx = binarysToints(printBits(rwlx));
		int[] yd = new int[4];
		yd = binarysToints(printBits(yc));
		int[] mbd = new int[4];
		mbd = binarysToints(printBits(mbc));
		int[] xf = new int[4];
		xf = binarysToints(printBits(xfwc));
		int[] zxjd = new int[4];
		zxjd = binarysToints(printBits(hczxjd));


		int[] trayarry = new int[24];
		for(int i=0;i<4;i++){
			trayarry[i] = task[i];
		}
		for(int i=0;i<4;i++){
			trayarry[4+i] = lx[i];
		}
		for(int i=0;i<4;i++){
			trayarry[8+i] = yd[i];
		}
		for(int i=0;i<4;i++){
			trayarry[12+i] = mbd[i];
		}
		for(int i=0;i<4;i++){
			trayarry[16+i] = xf[i];
		}
		for(int i=0;i<4;i++){
			trayarry[16+i] = zxjd[i];
		}
		int[] d1=trayarry;
		int a=0;
		for(int i=0;i<d1.length;i++){
			//System.out.print(d1[i]+" ");
			//System.out.println();
			a=a+d1[i];
		}
		return a;
	}
	///字节转整型
	public static int getcdj(byte a1,byte a2,byte a3,byte a4,byte a5,byte a6,byte a7,byte a8,
			byte a9,byte a10,byte a11,byte a12,byte a13,byte a14,byte a15,byte a16,
			byte a17,byte a18,byte a19,byte a20,byte a21,byte a22,byte a23,byte a24,byte a25){
		int[] trayarry = new int[25];
		trayarry[0] = binarysToints8(printBits(a1));
		trayarry[1] = binarysToints8(printBits(a2));
		trayarry[2] = binarysToints8(printBits(a3));
		trayarry[3] = binarysToints8(printBits(a4));
		trayarry[4] = binarysToints8(printBits(a5));
		trayarry[5] = binarysToints8(printBits(a6));
		trayarry[6] = binarysToints8(printBits(a7));
		trayarry[7] = binarysToints8(printBits(a8));
		trayarry[8] = binarysToints8(printBits(a9));
		trayarry[9] = binarysToints8(printBits(a10));
		trayarry[10] = binarysToints8(printBits(a11));
		trayarry[11] = binarysToints8(printBits(a12));
		trayarry[12] = binarysToints8(printBits(a13));
		trayarry[13] = binarysToints8(printBits(a14));
		trayarry[14] = binarysToints8(printBits(a15));
		trayarry[15] = binarysToints8(printBits(a16));
		trayarry[16] = binarysToints8(printBits(a17));
		trayarry[17] = binarysToints8(printBits(a18));
		trayarry[18] = binarysToints8(printBits(a19));
		trayarry[19] = binarysToints8(printBits(a20));
		trayarry[20] = binarysToints8(printBits(a21));
		trayarry[21] = binarysToints8(printBits(a22));
		trayarry[22] = binarysToints8(printBits(a23));
		trayarry[23] = binarysToints8(printBits(a24));
		trayarry[24] = binarysToints8(printBits(a25));
		int[] d1=trayarry;
		for(int i=0;i<d1.length;i++)
		System.out.print(d1[i]+" ");
		System.out.println();

//		int[] b= new int[2];
//		//**将a数组经过crc16多出来的两个字节 反转 能后存到另外一个两个字节的数组中**//*
//		for(int i=2,j=0;i>0;i--,j++){
//			b[j] = (int)d1[i-1+trayarry.length];
//		}
		return BytesToIntx(d1);
	}
	//int 转成4字节
	public static byte[] int2byte(int res) {///Java中10进制转byte[]
	       byte[] targets = new byte[4];
	       targets[3] = (byte) (res & 0xff);// 最低位
	       targets[2] = (byte) ((res >> 8) & 0xff);// 次低位
	       targets[1] = (byte) ((res >> 16) & 0xff);// 次高位
	       targets[0] = (byte) (res >>> 24);// 最高位,无符号右移。
	       return targets;
	   }
	//int 转2字节
	public static byte[] intbyte(int res) {///Java中10进制转byte[]
		byte[] targets = new byte[2];
		targets[1] = (byte) ((res >> 0) & 0xff);// 次高位
		targets[0] = (byte) (res >>> 8);// 最高位,无符号右移。
		return targets;
	}
	//long 转8字节
	public static byte[]  longTobyte(long res){
		return ByteBuffer.allocate(Long.SIZE/Byte.SIZE).putLong(res).array();
	}

	//8字节转 long

	public static long bytesToLong(byte[] input, int offset, boolean littleEndian) {
		// 将byte[] 封装为 ByteBuffer
		ByteBuffer buffer = ByteBuffer.wrap(input,offset,8);
		if(littleEndian){
			// ByteBuffer.order(ByteOrder) 方法指定字节序,即大小端模式(BIG_ENDIAN/LITTLE_ENDIAN)
			// ByteBuffer 默认为大端(BIG_ENDIAN)模式
			buffer.order(ByteOrder.LITTLE_ENDIAN);
		}
		return buffer.getLong();
	}

	//取返回结果中第5，6 位判断返回结果类型
	public static int[] getMl (byte[] arr,int offset){
		int values[]=new int[offset];
		for(int i=0;i<values.length;i++) {
			values[i] = (int) ((arr[5] & 0xFF)
					| ((arr[4] << 8) & 0xFF00));
			Logger.info(values[i]);
		}
		return values ;
	}

	public static boolean isNumber(String str){
		Pattern patten = Pattern.compile("[0-9]*");
		Matcher isMun = patten.matcher(str.charAt(0)+"");
		if(!isMun.matches()){
			return false;
		}
		return true;
	}

    public static int getJYM_RGV(int taskno, int YP, int YL, int MBP, int MBL, int MLFS, int xfwc) {
		//将整形任务号转为32位，能后转为四个字节，最后转为整形组4
		int[] task = new int[4];
		task = binarysToints(printBits(taskno));
		int[] yp = new int[4];
		yp = binarysToints(printBits(YP));
		int[] yl = new int[4];
		yl = binarysToints(printBits(YL));
		int[] mbp = new int[4];
		mbp = binarysToints(printBits(MBP));
		int[] mbl = new int[4];
		mbl = binarysToints(printBits(MBL));
		int[] mlfs = new int[4];
		mlfs = binarysToints(printBits(MLFS));
		int[] wc = new int[4];
		wc = binarysToints(printBits(xfwc));
		int[] trayarry = new int[40];
		for(int i=0;i<4;i++){
			trayarry[i] = task[i];
		}
		for(int i=0;i<4;i++){
			trayarry[4+i] = yp[i];
		}
		for(int i=0;i<4;i++){
			trayarry[8+i] = yl[i];
		}

		for(int i=0;i<4;i++){
			trayarry[12+i] = mbp[i];
		}
		for(int i=0;i<4;i++){
			trayarry[16+i] = mbl[i];
		}

		for(int i=0;i<4;i++){
			trayarry[20+i] = mlfs[i];
		}
		for(int i=0;i<4;i++){
			trayarry[24+i] = wc[i];
		}
		int[] d1=trayarry;
		int a=0;
		for(int i=0;i<d1.length;i++){
			//System.out.print(d1[i]+" ");
			//System.out.println();
			a=a+d1[i];
		}
		return a;
    }
}
